<?php
/**
 * Junction_Class
 * 
 * PHP Class
 * 
 * @author Patrick J. Mizer <patrick.mizer@gmail.com>
 */

using("Junction_Column");  
 
class Junction_Class
{
	/**
	 * Class's name
	 * 
	 * @var string
	 */
	private $_name;
	
	/**
	 * Tables which make up class.
	 * 
	 * @var array Junction_Table
	 */
	private $_tables;
	
	/**
	 * Class's primary key attribute
	 * 
	 * @var string
	 */
	private $_pkName;
	
	/**
	 * Class's primary key column
	 * 
	 * @var Junction_Column
	 */
	private $_pkColumn;	
	
	/**
	 * Class's attributes 
	 * 
	 * @var array string => Junction_Column
	 */
	private $_attributes;
	
	/**
	 * Junction_Class Constructor
	 * 
	 * @param string class name
	 */
	public function __construct($name)
	{
		$this->_name 	= $name;
		$this->_tables 	= array();
	}
	
	/**
	 * Setter for primary key
	 * 
	 * @param string PK name
	 * @param Junction_Column PK column
	 * @return void
	 */
	public function setPrimaryKey($key, Junction_Column $col)
	{
		$this->_pkName 		= $key;
		$this->_pkColumn 	= $col;
	}
	
	/**
	 * Adds to $_attributes hash
	 * 
	 * @param string key
	 * @param Junction_Column
	 */
	public function setAttribute($key, Junction_Column $value)
	{
		$this->_attributes[$key] = $value;
		if(!in_array($value->getTable(), $this->_tables)){
			$this->_tables[] = $value->getTable();
		}
	}
	
	/**
	 * Getter for primary key name.
	 * 
	 * @return string primary key name.
	 */
	public function getPrimaryKeyName()
	{
		return $this->_pkName;
	}
	
	/**
	 * Getters for ptimary key column
	 * 
	 * @return Junction_Column
	 */
	public function getPrimaryKeyColumn()
	{
		return $this->_pkColumn;
	}
	
	/**
	 * Getter for attributes.
	 * 
	 * @return array string => Junction_Column
	 */
	public function getAttributes()
	{
		return $this->_attributes;
	}
	
	/**
	 * Getter for attribute
	 * 
	 * @param string key
	 * @return Junction_Column
	 */
	public function getAttribute($key)
	{
		return $this->_attributes[$key];
	}
	
	/**
	 * Getter for tables
	 * 
	 * @return array Junction_Tables
	 */
	public function getTables()
	{
		return $this->_tables;
	}
}
?>